//
//  TZTabBarController.swift
//  weibo_Swift
//
//  Created by 涂真 on 15/12/15.
//  Copyright © 2015年 涂真. All rights reserved.
//

import UIKit

class TZMainController: UITabBarController {
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = UIColor.whiteColor()
        //使用自定义TabBar
        let mainTabBar = TZMainTabBar()
        setValue(mainTabBar, forKey: "tabBar")
        //添加主页
        let home = TZHomeController()
        addNavController(home, title: "主页", iconName: "tabbar_home")
        
        //添加消息
        let message = TZMessageController()
        addNavController(message, title: "消息", iconName: "tabbar_message_center")
        
        //添加发现
        let discover = TZDiscoverController()
        addNavController(discover, title: "发现", iconName: "tabbar_discover")
        
        //添加我
        let frofile = TZFrofileController()
        addNavController(frofile, title: "我", iconName: "tabbar_profile")
    }
   //MARK:- 为主控制器添加子控制器
    func addNavController(controller:UITableViewController,title:String,iconName:String){
        self.addChildViewController( UINavigationController(rootViewController: controller))
        controller.title = title
        controller.tabBarItem.image = UIImage(named: iconName)
        let selectedImageName = iconName+"_highlighted"
        //设置图片渲染
        controller.tabBarItem.selectedImage = UIImage(named: selectedImageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置文字颜色
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)

        
        
    }
}
